<?php
// Require compiled in 1 class Core with merged Zend Framework bootstrap files for fast loading
// Also required merged models
//require_once '../classes/Core.php';
require_once dirname(__FILE__) . '/../classes/Bootstrap.php';
try {
	
	
	// Get front controller instance
	$front = Zend_Controller_Front::getInstance();
	// Set modular structure directories
	$front->addModuleDirectory(BASE_DIR . '/application/modules');
	//$router = new Zend_Controller_Router_Rewrite();
	//$front->setRouter($router);
	
	// Register charset plugin
	$front->registerPlugin(new DefaultCharsetPlugin());
	$front->registerPlugin(new HtmlCompressorPlugin());

	// Init Smarty View as default renderer
	//$view = new Zend_View();
	//$view = Smarty_View::getInstance();
	$view = new Zend_View();
        $view->doctype('XHTML1_STRICT');
        $view->addHelperPath(dirname(dirname(__FILE__)) . "/application/modules/default/views/helpers", "Views_Helpers");
        $view->addHelperPath(dirname(dirname(__FILE__)) . "/library/ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
        Zend_Controller_Action_HelperBroker::addHelper(
            new ZendX_JQuery_Controller_Action_Helper_AutoComplete()
        );
//	$view = new Dwoo_Adapters_ZendFramework_View(array(
//	            'engine' => array(
//                  'compileDir' => BASE_DIR . '/tmp/dwoo_templates', // calls the $dwoo->setCompileDir() method
//                  'cacheDir' => BASE_DIR . '/tmp/dwoo_cache' // calls the $dwoo->setCacheDir() method
//            ),
//            'compiler' => array(
//                  'autoEscape' => true // calls $compiler->setAutoEscape()
//            )));
    $view->addBasePath("/application/layouts/blocks");
//    $pluginProxy = new Dwoo_Adapters_ZendFramework_PluginProxy(new Zend_View());
//	$view->setPluginProxy($pluginProxy);
//	$view->setHelperPath('ZendX/JQuery/View/Helper/');
    Config::getInstance();
	$renderer = new Zend_Controller_Action_Helper_ViewRenderer();
	$renderer->setView($view);
	$renderer->setViewSuffix('tpl');
	// Set view renderer helper
	//$jqueryHelper = new ZendX_JQuery_View_Helper_JQuery();
	//Zend_Controller_Action_HelperBroker::addPath(, 'ZendX_JQuery_View_Helper');
	Zend_Controller_Action_HelperBroker::addHelper($renderer);
	//Zend_Controller_Action_HelperBroker::addHelper($jqueryHelper);
	Zend_Controller_Action_HelperBroker::addPrefix('Helpers');
	
	// Init Zend_Layout
	$layout = Zend_Layout::startMvc();
	$layout->setViewSuffix('tpl');
	// Switch off error handler plugin
	$front->setParam('noErrorHandler', true);
	// Throw exceptions in dispatch loop
	$front->throwExceptions(true);

	// Set return response flag
	$front->returnResponse(true);

	// Create request object
	$request = new Request();

	// Dispatch request
	$response = $front->dispatch($request);
	// Output response
	$response->sendResponse();
} catch (Exception $e) {
	// Go to php manual
	if ($e instanceof Zend_Controller_Dispatcher_Exception || $e instanceof Zend_Controller_Action_Exception) {
		$e->getMessage();
		$request->setModuleName('default');
		$request->setControllerName('error');
		$request->setActionName('not-found');
		try {
			$response = $front->getResponse();
			$front->getDispatcher()->dispatch($request, $response);
			$response->setHttpResponseCode(404);
			$response->sendResponse();
			return ;
		} catch (Exception $e) {
		}
	}

	// Show exception
	//require 'ErrorLowlevel.php';
        //Zend_Debug::dump(BASE_DIR, $label="zu"."\n \t&nbsp;", $echo=true); exit;
        require "../classes/ErrorLowlevel.php";

}
//$timeEnd = microtime(true);
//d($timeEnd-$timeStart);
